<template>
    <div>
        <h2>添加英雄页面</h2>
        <p>英雄名称：<input type="text" v-model="name"></p>
        <p>英雄密码：<input type="password" v-model="password"></p>
        <p>英雄图片：<input type="file" @change="get_file($event)"></p>
        <p>英雄归属：
           <select v-model="cates">
                <option v-for="(i,d) in cate" :value="i.id" :key="d">{{i.name}}</option>

           </select>
        </p>
        <p><input type="button" value="添加英雄" @click="addhero()"></p>
    </div>
</template>

<script>
import axios from "axios"
import {get_game} from "../axios_api/api.js"
export default {
    name:"addhero",
    data() {
        return {
            name:"",
            password:"",
            pic:"",
            cate:"",
            cates:"",
                           
        }
    },
    methods:{
        get_file(event){
            this.file = event.target.files[0]
        },
        addhero(){
           let formdata = new FormData()
           formdata.append("name",this.name)
           formdata.append("password",this.password)
           formdata.append("pic",this.file)
           formdata.append("cate",this.cates)
           axios({
                url:'http://127.0.0.1:8000/app01/addhero/',
                method:'post',
                data:formdata
            }).then(res=>{
                console.log(res.data)
            })
        },
        get_game(){
            axios({
                url:"http://127.0.0.1:8000/app01/getgame/",
                method:"get",
            }).then(res=>{
                console.log(res.data)
                this.cate=res.data.data
            })
                
            
        }
    },
    created() {
        this.get_game()  
    },
}

</script>

<style>

</style>
